package com.kgcx.organization.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.organization.domain.Auto;
import com.kgcx.organization.domain.AutoBrand;
import com.kgcx.organization.domain.AutoModel;
import com.kgcx.organization.service.AutoBrandService;
import com.kgcx.organization.service.AutoModelService;
import com.kgcx.organization.service.AutoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "车辆接口", tags = "车辆接口")
@RestController
@RequestMapping("auto")
public class AutoController extends BaseController {
    @Autowired
    private AutoService autoService;

    @Autowired
    private AutoBrandService autoBrandService;

    @Autowired
    private AutoModelService autoModelService;

    @ApiOperation(value = "查询车辆", httpMethod = "GET", notes = "这是用来查询车辆的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "车辆ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getAuto")
    public ReturnData<Auto> getAuto() {
        RequestData requestData = this.getRequestData();
        Auto auto = autoService.getAuto(requestData.getLong("kid"));
        return new ReturnData<>(auto);
    }

    @ApiOperation(value = "查询车辆", httpMethod = "GET", notes = "这是用来查询车辆的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "cityId", value = "城市ID", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "supplierId", value = "供应商ID", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "autoNoLike", value = "车牌号", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "ownerNameLike", value = "车主", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "source", value = "来源，1=自营，2=加盟", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "createTime", value = "录入时间", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "nextFixDate", value = "下次年检时间", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "autoBrandId", value = "车辆品牌id", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping("getAutoList")
    public ReturnData<List<Auto>> getAutoList() {
        RequestData requestData = this.getRequestData();
        List<Auto> autoList = autoService.getAutoList(requestData);
        return new ReturnData<>(autoList);
    }

    @ApiOperation(value = "新增车辆", httpMethod = "POST", notes = "这是用来新增车辆的接口")
    @PostMapping("addAuto")
    public ReturnData addAuto(@RequestBody Auto auto) {
        autoService.addAuto(auto);
        return new ReturnData();
    }

    @ApiOperation(value = "修改车辆", httpMethod = "POST", notes = "这是用来修改车辆的接口")
    @PostMapping("updateAuto")
    public ReturnData updateAuto(@RequestBody Auto auto) {
        autoService.updateAuto(auto);
        return new ReturnData();
    }

    @ApiOperation(value = "删除车辆", httpMethod = "POST", notes = "这是用来删除车辆的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeAuto")
    public ReturnData removeAuto(@RequestParam Long kid) {
        autoService.removeAuto(kid);
        return new ReturnData();
    }


    @ApiOperation(value = "查询车辆品牌", httpMethod = "GET", notes = "这是用来查询车辆品牌的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "车辆品牌ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getAutoBrand")
    public ReturnData<AutoBrand> getAutoBrand() {
        RequestData requestData = this.getRequestData();
        AutoBrand autoBrand = autoBrandService.getAutoBrand(requestData.getLong("kid"));
        return new ReturnData<>(autoBrand);
    }

    @ApiOperation(value = "查询车辆品牌", httpMethod = "GET", notes = "这是用来查询车辆品牌的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("getAutoBrandList")
    public ReturnData<List<AutoBrand>> getAutoBrandList() {
        RequestData requestData = this.getRequestData();
        List<AutoBrand> autoBrandList = autoBrandService.getAutoBrandList(requestData);
        return new ReturnData<>(autoBrandList);
    }

    @ApiOperation(value = "新增车辆品牌", httpMethod = "POST", notes = "这是用来新增车辆品牌的接口")
    @PostMapping("addAutoBrand")
    public ReturnData addAutoBrand(@RequestBody AutoBrand autoBrand) {
        autoBrandService.addAutoBrand(autoBrand);
        return new ReturnData();
    }

    @ApiOperation(value = "修改车辆品牌", httpMethod = "POST", notes = "这是用来修改车辆品牌的接口")
    @PostMapping("updateAutoBrand")
    public ReturnData updateAutoBrand(@RequestBody AutoBrand autoBrand) {
        autoBrandService.updateAutoBrand(autoBrand);
        return new ReturnData();
    }

    @ApiOperation(value = "删除车辆品牌", httpMethod = "POST", notes = "这是用来删除车辆品牌的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeAutoBrand")
    public ReturnData removeAutoBrand(@RequestParam Long kid) {
        autoBrandService.removeAutoBrand(kid);
        return new ReturnData();
    }

    @ApiOperation(value = "车辆绑定司机", httpMethod = "POST", notes = "这是用来车辆绑定司机的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "autoId", value = "车辆ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "driverId", value = "司机ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class)
    })
    @PostMapping("bindDriver")
    public ReturnData bindDriver(@RequestParam Long autoId, @RequestParam Long driverId) {
        autoService.bindDriver(autoId, driverId);
        return new ReturnData();
    }

    @ApiOperation(value = "车辆解除绑定司机", httpMethod = "POST", notes = "这是用来车辆解除绑定司机的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "autoId", value = "车辆ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "driverId", value = "司机ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class)
    })
    @PostMapping("unBindDriver")
    public ReturnData unBindDriver(@RequestParam Long autoId, @RequestParam Long driverId) {
        autoService.unBindDriver(autoId, driverId);
        return new ReturnData();
    }


    @ApiOperation(value = "查询车辆型号", httpMethod = "GET", notes = "这是用来查询车辆型号的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "车辆型号ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getAutoModel")
    public ReturnData<AutoModel> getAutoModel() {
        RequestData requestData = this.getRequestData();
        AutoModel autoModel = autoModelService.getAutoModel(requestData.getLong("kid"));
        return new ReturnData<>(autoModel);
    }

    @ApiOperation(value = "查询车辆型号", httpMethod = "GET", notes = "这是用来查询车辆型号的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("getAutoModelList")
    public ReturnData<List<AutoModel>> getAutoModelList() {
        RequestData requestData = this.getRequestData();
        List<AutoModel> autoModelList = autoModelService.getAutoModelList(requestData);
        return new ReturnData<>(autoModelList);
    }

    @ApiOperation(value = "新增车辆型号", httpMethod = "POST", notes = "这是用来新增车辆型号的接口")
    @PostMapping("addAutoModel")
    public ReturnData addAutoModel(@RequestBody AutoModel autoModel) {
        autoModelService.addAutoModel(autoModel);
        return new ReturnData();
    }

    @ApiOperation(value = "修改车辆型号", httpMethod = "POST", notes = "这是用来修改车辆型号的接口")
    @PostMapping("updateAutoModel")
    public ReturnData updateAutoModel(@RequestBody AutoModel autoModel) {
        autoModelService.updateAutoModel(autoModel);
        return new ReturnData();
    }

    @ApiOperation(value = "删除车辆型号", httpMethod = "POST", notes = "这是用来删除车辆型号的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeAutoModel")
    public ReturnData removeAutoModel(@RequestParam Long kid) {
        autoModelService.removeAutoModel(kid);
        return new ReturnData();
    }

    /**
     * 专给监管平台提供查询
     * @return
     */
    @ApiOperation(value = "监管平台查询车辆", httpMethod = "GET", notes = "这是用来给监管平台查询车辆的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "cityId", value = "城市ID", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "supplierId", value = "供应商ID", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "autoNo", value = "车牌号", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "ownerName", value = "车主", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "source", value = "来源，1=自营，2=加盟", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),

    })
    @GetMapping("queryAutoWithPage")
    public ReturnData<List<Auto>> queryAutoWithPage() {
        RequestData requestData = this.getRequestData();
        List<Auto> autoList = autoService.queryAutoWithPage(requestData);
        return new ReturnData<>(autoList);
    }

    /**
     * 专给监管平台提供查询
     * @return
     */
    @ApiOperation(value = "监管平台查询车辆保险", httpMethod = "GET", notes = "这是用来给监管平台查询车辆保险的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "cityId", value = "城市ID", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "supplierId", value = "供应商ID", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "autoNo", value = "车牌号", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "ownerName", value = "车主", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "source", value = "来源，1=自营，2=加盟", required = false, paramType = "query", dataType = "Long", dataTypeClass = Long.class),

    })
    @GetMapping("queryInsuranceWithPage")
    public ReturnData<List<Auto>> queryInsuranceWithPage() {
        RequestData requestData = this.getRequestData();
        List<Auto> autoList = autoService.queryInsuranceWithPage(requestData);
        return new ReturnData<>(autoList);
    }
}
